Skip to main content
Access via:io.contexts

8 Methods

all()⚓︎

() => string[]

Returns all existing context names. Using the context name you can subscribe for context changes, updates or set context values.

destroy()⚓︎

(name: string) => Promise<any>

Destroys a context and all the data associated with it

Parameters (1)

Name Type Required Description
name⚓︎ string

Name of the context to be removed

get()⚓︎

(name: string) => Promise<any>

Return the context data immediately or asynchronously as soon as any data becomes available.

Parameters (1)

Name Type Required Description
name⚓︎ string

Name of the context from which you want to get data.

set()⚓︎

(name: string, data: any) => Promise<void>

Replaces a context. All properties of the specified context object will be removed and replaced with the ones supplied in the data parameter.

Parameters (2)

Name Type Required Description
name⚓︎ string

Name of the context to be replaced.

data⚓︎ any

The object that will be applied to the context.

setPath()⚓︎

(name: string, path: string, data: any) => Promise<void>

Sets a path in the context to some value. Use this to update values that are not on top level in the context.

Parameters (3)

Name Type Required Description
name⚓︎ string

Name of the context to be updated

path⚓︎ string

Path to be updated. Path should be in the format "prop1.prop2"

data⚓︎ any

The object that will be applied to the path

setPaths()⚓︎

(name: string, paths: PathValue[]) => Promise<void>

Sets multiple paths in the context to some values in a single command.

Parameters (2)

Name Type Required Description
name⚓︎ string

Name of the context to be updated

paths⚓︎ PathValue[]

Array of paths and their values to be updated. Path should be in the format "prop1.prop2"

subscribe()⚓︎

(name: string, callback: (data: any, delta: any, removed: string[], unsubscribe: () => void, extraData?: any) => void) => Promise<() => void>

Subscribes for context events. Returns an unsubscribe function which you can use to stop receiving context updates.

Parameters (2)

Name Type Required Description
name⚓︎ string

Name of the context to which you want to subscribe.

callback⚓︎ (data: any, delta: any, removed: string[], unsubscribe: () => void, extraData?: any) => void

Function that will handle the updates.

update()⚓︎

(name: string, data: any) => Promise<void>

Updates a context with the supplied object. This method updates only the specified context properties. Any other existing context properties will remain intact. If the context does not exist, the update() method will create it.

Parameters (2)

Name Type Required Description
name⚓︎ string

Name of the context to be updated.

data⚓︎ any

The object that will be applied to the context.

Example

io.contexts.update("app-styling", {
    backgroundColor: "red",
    alternativeColor: "green",
});